package com.example.maxboxtwo.components.function.Light;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View;

import androidx.annotation.Nullable;

import com.example.maxboxtwo.R;
// this is a invalid view
public class LightView extends View {
    private Bitmap bitmap;
    private Paint paint;

    public Bitmap getBitmap() {
        return bitmap;
    }

    public void setBitmap(Bitmap bitmap) {
        this.bitmap = bitmap;
    }

    public LightView(Context context) {
        super(context);
    }

    public LightView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    protected void onSizeChanged(int w, int h, int oldw, int oldh) {
        if(bitmap==null)
            setBitmap(bitmap.createScaledBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.flashlight_level0),w,h,true));

        if(paint==null){
            paint = new Paint();
            paint.setAlpha(1);
            paint.setDither(true);
            paint.setStyle(Paint.Style.STROKE);
        }
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        canvas.drawBitmap(getBitmap(),getWidth(),getHeight(),paint);
    }

}
